package bishizhuanyong.sl0;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int n = s.nextInt();
        for (int i=0;i<n;i++){
            String s1=s.next();
            String s2=s.next();
            process(s1,s2);
        }
    }

    public static void process(String s1,String s2){
        if (s1.equals(s2)){
            System.out.println("YES");
            return;
        }
        if (s1.length()>s2.length()||(s1.length()==s2.length()&&!s1.equals(s2))){
            System.out.println("NO");
            return;
        }
        ArrayList<info> s1i = getInfo(s1);
        ArrayList<info> s2i = getInfo(s2);
        if (!dis(s1,s2)){
            System.out.println("NO");
            return;
        }
        for (int i=0;i<s1i.size();i++){
            if (s1i.get(i).c!=s2i.get(i).c||s1i.get(i).count>s2i.get(i).count){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

    public static boolean dis(String s1,String s2){
        int[] hash=new int[26];
        for (int i=0;i<s1.length();i++)
            hash[s1.charAt(i)-'a']++;
        for (int i=0;i<s2.length();i++){
            if (hash[s2.charAt(i)-'a']==0)
                return false;
        }
        return true;
    }

    static class info{
        char c;
        int count;

        info(char cc,int ii){
            c=cc;
            count=ii;
        }
    }

    public static ArrayList<info> getInfo(String s){
        ArrayList<info> res=new ArrayList<>();
        int index=0;
        while (index<s.length()){
            int count=1;
            while (index<s.length()-1&&s.charAt(index+1)==s.charAt(index)){
                count++;
                index++;
            }
            info tmp=new info(s.charAt(index),count);
            res.add(tmp);
            index++;
        }
        return res;
    }
}
